#!/bin/sh
# Copyright (c) 2011, bkil.hu
# This program is free software and can be distributed under the terms of
# the GNU General Public License v2,
# see COPYING for detailed licensing terms.

. sh_lib.sh

try(){
 PEN=$1
# umount $PEN 2>/dev/null
 mount $PEN &&
  echo "found $PEN"
}

i_geany(){
 nice tar -xzf $SRC/geany$VER.tar.gz -C $DEST ||exit 1
}

i_erlang(){
 mkdir -p $DEST/autotested ||exit 1
 mkdir -p $DEST/data ||exit 1
 nice tar -xzf $SRC/erlbin$VER.tar.gz -C $DEST ||exit 1
}

i_svn(){
 nice tar -xzf $SRC/svnbin$VER.tar.gz -C $DEST ||exit 1
}

i_emacs(){
 [ "$VER" = 32 ] &&
  nice tar -xzf $SRC/emacs32.tar.gz -C $DEST ||exit 1
}

i_firefox(){
 nice tar -xzf $SRC/firefox-*.*.tar.gz -C $DEST ||exit 1
 nice tar -xzf $SRC/flash_player$VER.tar.gz -C $DEST ||exit 1
 nice tar -xzf $SRC/_mozilla.tar.gz -C $DEST ||exit 1
#mkdir -p $DEST/.mozilla ||exit 1
}

main(){
 case `uname -m` in
  "i686"*) VER=32 ;;
  "amd64"*) VER=64 ;;
  "x86_64"*) VER=64 ;;
  *) uname -a;exit 1 ;;
 esac
 VER=32
 try /media/pendrive || try /mnt/pendrive || try /media/KINGSTON # || exit 1
 SRC=$PEN/__/bin/
 [ -d "$SRC" ] || exit 1
 DEST=/tmp/$USER
 mkdir -p $DEST ||exit 1

 dn i_firefox
 dn i_geany
 dn i_emacs
 dn i_svn
 dn i_erlang
 dn sleep 1
 dn umount $PEN ||exit 1

 echo ok ${VER}-bit $DEST
}

main "$@"

